package com.feng.security.config;

import com.feng.common.utils.SecurityUtil;
import com.feng.security.domain.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Feng
 * @since 2022/4/17 22:01
 */
@Component("er")
public class MyExpressionRoot {

    public boolean check(String authority){
        //获取当前用户的权限
        LoginUser loginUser = SecurityUtil.getCurrentUserDetails();
        List<String> permissions = loginUser.getPermissions();
        //判断用户权限集合中是否存在authority
        return permissions.contains(authority);
    }
}
